package com.iaz.tech.tools.common.flow.impl;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.iaz.tech.tools.common.flow.IFlowAble;

import lombok.Data;
import lombok.EqualsAndHashCode;

/**
 * Else if 语句
 */
@EqualsAndHashCode(callSuper = true)
@Data
public class ElseIfFlow extends FlowsGroup {
	/**
     * 日志
     */
	private final static Logger logger = (Logger) LoggerFactory.getLogger(ElseIfFlow.class);
	private IFlowAble boundary = null;
	/**
     * 执行流程
     */
    @Override
    public Object executeFlow(Object property) {
        Object result = null;
		try {
			if(boundary == null) {
				logger.warn("ElseIfFlow boundary is null");
				return result;
			}
			Object boundaryResult =	boundary.executeFlow(property);
			if (boundaryResult == null) {
				logger.warn("ElseIfFlow boundaryResult is null");
				return result;
			}
			if (boundaryResult instanceof Boolean) {
				if ((Boolean) boundaryResult) {
					result = super.executeFlow(property);
				}
			}
		} catch (Exception e) {
			logger.error("ElseIfFlow executeFlow error", e);
		}
        return result;
    }

}
